
    use:  'ie.ondevice.utility.statemachine.State';
    
    StateMachine.implement
    (
        {
            /**
             * @private
             * The state machines current state. You should delegate all methods
             * to the state machines current state.
             * @type {State}
             */
            state: null
            
            /**
             * Set the machines state. If permitted, the old states exit
             * method will be invoked, the new state will become the machines
             * state moving forward, and its enter method will be invoked.
             * 
             * @param {State} newState
             * @return {void}
             * @throws StateTransitionException
             */
        ,   setState: function (newState) 
            {
                if (this.canEnterState(newState)) 
                {
                    try 
                    {
                        this.state.exit();
                        this.state= newState;
                        this.state.enter();
                    }
                    catch (thrown) 
                    {
                        throw new StateTransitionException(thrown);
                    }
                }
            }
            
            /**
             * Determine if the state machine can enter the state provided.
             * Override this method to implement your own transition logic.
             * You can assume that this.state is the current state, and subject
             * to this method returning true, the state argument will become the
             * machines next state.
             * 
             * The default implement return true as long as the argumentsupplied 
             * is a state object, and is not the machines current state object.
             * 
             * @param {Object} state
             * @return {Boolean}
             * @throws {Error}
             */
        ,   canEnterState: function (state) 
            {
                if (State.is(state)) 
                {
                    return this.state !== state;
                }
                
                throw new TypeError('State expected');
            }
        }
    );
    
    /**
     * Create a new state machine. The state machine class as it stands should
     * be considered abstract, and is best suited to subclassing. You can
     * however use this as a member to compose classes.
     * @constructor
     */
    function StateMachine () 
    {
        this.state= new State(this); // null state
    };
    
    
    StateTransitionException.inherit(Error);
    function StateTransitionException (cause) 
    {
        Error.call(this, 'State transition exception: ' + cause);
        this.cause= cause;
    };

